package com.ydkfjs.controller;

import com.ydkfjs.common.Result;
import com.ydkfjs.model.dto.TypeRequest;
import com.ydkfjs.model.po.Type;
import com.ydkfjs.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: hb
 * @CreateTime: 2024-04-22 18:59
 * @Version: 1.0
 */
@Api(tags = "类别模块")
@RestController
@RequestMapping("/type")
public class TypeController {

    private final TypeService typeService;

    public TypeController(TypeService typeService) {
        this.typeService = typeService;
    }

    @ApiOperation(value = "添加类别 1食物 2运动")
    @PostMapping("/add")
    public Result<?> add(@RequestBody TypeRequest typeRequest) {
        typeService.add(typeRequest);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "获取类别 1食物 2运动")
    @GetMapping("/getById")
    public Result<?> get(@RequestParam Integer kind) {
        List<Type> list = typeService.get(kind);
        return Result.success("获取成功",list);
    }

    @ApiOperation("删除类别")
    @DeleteMapping("/deleteById")
    public Result<?> delete(@RequestParam Long id){
        typeService.delete(id);
        return Result.success("删除成功");
    }

}
